package com.cwj.juc;

import java.util.concurrent.TimeUnit;

/**
 * @author: Chenwujie
 * @date: 2021-07-14 15:40
 */
public class VisibilityTest {
    private static  int i;
    private static boolean reddy;

    public static void main(String[] args) {
        VisibilityTest.test();
    }

    private static class MyThread extends Thread{
        @Override
        public void run() {
            while(!reddy){
                Thread.yield();
//                System.out.println("while");
            }
            System.out.println(i);
        }
    }

    public static void test() {
        new MyThread().start();
        try {
            TimeUnit.MILLISECONDS.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        i = 47;
        reddy = true;
    }

}
